package main;

import java.applet.Applet;
import java.applet.AudioClip;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.net.URL;


public class GameFrame extends Applet implements ICollider {

    /** physical rect. */
    protected Rectangle2D brickRectangle2d;
    /** object speed. */
    protected Point2D speed;
    /**
     * Default constructor.
     * @param x start point y
     * @param y start point x
     * @param w width
     * @param h height
     */
    public GameFrame(final double x, final double y, final double w, final double h)
    {
        brickRectangle2d = new Rectangle2D.Float();
        brickRectangle2d.setRect(x, y, w, h);
        speed = new Point2D.Double(0, 0);
    }
    @Override
    public Point2D calculateNextPosition(final float timeDelta) {
        double x = getPosition().getX() + getSpeed().getX() * timeDelta;
        double y = getPosition().getY() + getSpeed().getY() * timeDelta;
        Point2D newPos = new Point2D.Double(x, y);
        return newPos;
    }

    @Override
    public final Point2D getMax() {
        Point2D max = new Point2D.Double(brickRectangle2d.getMaxX(),
                brickRectangle2d.getMaxY());
        return max;
    }

    @Override
    public final Point2D getMin() {
        Point2D min = new Point2D.Double(brickRectangle2d.getMinX(),
                brickRectangle2d.getMinY());
        return min;
    }

    @Override
    public final Point2D getPosition() {
        return new Point2D.Double(brickRectangle2d.getCenterX(),
                brickRectangle2d.getCenterY());
    }

    @Override
    public final Point2D getSpeed() {
        return speed;
    }

    @Override
    public boolean onHit(final ICollider hitBy) {
        return false;
    }

    @Override
    public final void setPosition(final Point2D pos) {
        double width = brickRectangle2d.getWidth();
        double height = brickRectangle2d.getHeight();
        double newX = pos.getX() - width / 2;
        double newY = pos.getY() - height / 2;
        brickRectangle2d.setRect(newX, newY, width, height);
    }

    @Override
    public final void setSpeed(final Point2D newSpeed) {
        this.speed = newSpeed;
    }


    @Override
    public void paint(Graphics g) {
        g.fillRect((int) brickRectangle2d.getX(),
                (int) brickRectangle2d.getY(), (int) brickRectangle2d
                        .getWidth(), (int) brickRectangle2d.getHeight());
    }
    @Override
    public void restoreLastPosition() {
        // TODO Auto-generated method stub
        
    }
    @Override
    public void saveLastPosition() {
        // TODO Auto-generated method stub
        
    }
}
